﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using yncTech.BusinessObjects;
using yncTech.Common;
using EntitySpaces.Interfaces;

public partial class Admin_NoSAPFin_NoSAPFin002b : AdminBasePage
{
    string[] boxIds;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["boxids"] != null)
        {
            boxIds = Request.QueryString["boxids"].TrimEnd(',').Split(',');
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < boxIds.Length; i++)
        {
            FinReceipt finReceipt = new FinReceipt();
            FinBox finBox = new FinBox();
            FinBoxReceipts finBoxReceipts = new FinBoxReceipts();
            string user = LoginUserInfo.CurrentUser.LoginName;
            DateTime today = DateTime.Now;


            using (esTransactionScope tr = new esTransactionScope())
            {
                decimal boxId = decimal.Parse(boxIds[i]);
                decimal receiptId = -1;

                finBox.LoadByPrimaryKey(boxId);
                FinReceiptCollection finReceiptCollection = new FinReceiptCollection();
                finReceiptCollection.Query.Where(finReceiptCollection.Query.BoxID==boxId);
                finReceiptCollection.Query.Load();
                if (finReceiptCollection.HasData)
                {
                    receiptId=finReceiptCollection[0].ReceiptID.Value;
                }
                finReceipt.LoadByPrimaryKey(receiptId);

                finBox.UpdatedBy = user;
                finBox.UpdatedDttm = today;
                finBox.VersionNo = finBox.VersionNo + 1;
                finBox.Save();

                finReceipt.EStorageStatus = drpEStorageStatus.SelectedValue;
                finReceipt.EStorageLocation = txtEStorageLocation.Text.Trim();

                if (!string.IsNullOrEmpty(txtNeedStoreYear.Text.Trim()))
                
                finReceipt.Comments = txtComments.Text.Trim();
                finReceipt.ManageUser = drpManageUser.SelectedItem.Text;
                finReceipt.UpdatedBy = user;
                finReceipt.UpdatedDttm = today;
                finReceipt.VersionNo = finReceipt.VersionNo + 1;
                finReceipt.Save();

                tr.Complete();

                
            }

        }

        WebHelper.CloseDialog(true);
        
        
        
    }
}